import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout';
import ResultShow from '@/views/project-management/ResultShow.vue'; // 根据你的项目结构调整路径

Vue.use(Router);

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/project-management',
    component: Layout,
    children: [
      {
        path: 'result-show/:id',
        component: ResultShow,
        name: 'ResultShow',
        meta: { title: '结果展示', icon: 'example', noCache: true },
        props: true // 允许路由参数作为组件的 props
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    children: [{
      path: 'index',
      name: 'User',
      component: () => import('@/views/user/index'),
      meta: { title: '用户管理', icon: 'el-icon-user-solid' }
    }]
  },
  
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
];

const createRouter = () => new Router({
  mode: 'history', // 如果你需要 history 模式，请取消注释
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
